FROM node:12.22.1-alpine as builder

WORKDIR /data/project/backend/frontend

COPY backend/frontend/package*.json ./
RUN npm config set registry https://registry.npm.taobao.org/ && npm install
COPY backend/frontend ./
RUN npm run build

FROM python:3.6-slim

LABEL Author="Pad0y<github.com/Pad0y>"
ENV LANG C.UTF-8 LC_ALL=C.UTF-8

WORKDIR /data/project/

# 拷贝项目代码
COPY . .

# 环境依赖安装
RUN sed -i s@/[a-z]*.debian.org/@/mirrors.aliyun.com/@g /etc/apt/sources.list \
    && pip3 config set global.index-url https://pypi.doubanio.com/simple/ \
    && apt-get update -y \
    && pip3 install -r requirements.txt --no-cache-dir \
    # 修改时区
    && ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
    && echo "Asia/Shanghai" > /etc/timezone \
    # 清理安装残留
    && rm -rf /var/cache/apt/* \
    && rm -rf /root/.cache \
    && rm -rf /tmp/*

# 删除vue源码
RUN rm -rf /data/project/backend/frontend
COPY --from=builder /data/project/backend/frontend backend/frontend

#部署端口
EXPOSE 8080

ENTRYPOINT  ["python3", "backend/main.py"]